
    new Vue({
        el: '#app',
        data() {
            return {
                tel: '',
                sms: '',
                isSend: false,  //禁用
                codeName: "发送验证码",
                totalTime: 5, //一般是60
                timer: '', //定时器
            }
        },
        watch: {},
        mounted: function () {
        },
        methods: {
            // 获取验证码
            getCode() {
                if (this.tel === '') {
                    this.$toast('手机号不能为空!')
                } else {
                    let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
                    if (reg.test(this.tel)) {
                        console.log(111)
                    }
                    this.countDown()
                }
            },
            // 注册
            onSubmit() {
                console.log('submit', this.tel, this.sms);
            },
            // 验证码倒计时
            countDown() {
                if (this.isSend) return

                this.isSend = true
                this.codeName = this.totalTime + 's后重新发送'
                let that = this
              this.timer = setInterval(() => {
                  if (that.totalTime <= 1) {
                    clearInterval(that.timer)
                    that.$nextTick(() => { 
                      that.codeName = '重新发送验证码'
                      that.totalTime = 5
                      that.isSend = false
                    })
                  } else {
                    that.$nextTick(() => {
                      that.totalTime--
                      that.codeName = that.totalTime + 's后重新发送'
                    }) 
                  }
                }, 1000)
            },
            // 获取url参数
            getParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                var r = window.location.search.substr(1).match(reg);  //匹配目标参数
                if (r != null) return unescape(r[2]);
                return null; //返回参数值
            }
        }
    });

